<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  	<style>
  		.addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  	</style>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>신규 이벤트 추가 - <small>새로운 이벤트를 추가하세요.</small></h2>
		</div>

		<form id="insertEvent" class="form-horizontal" role="form" method="post" action="listEvent.do" enctype="multipart/form-data">
			<fieldset>
				<div class="form-group">
					<label for="boardTitle" class="col-md-2 control-label">이벤트명</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="boardTitle" placeholder="이벤트명을 입력하세요" autofocus/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="brand" class="col-md-2 control-label">클라이언트</label>
					<div class="col-md-10">
						<select name="brand" class="form-control">
							<option>- 선택하세요 -</option>
							<c:forEach items="${brand}" var="brand">
								<option value="${brand.idBrand}">${brand.brandTitle}</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="eventImg" class="col-md-2 control-label">이미지 <span class="text-danger">(640x360)</span></label>
					<div class="col-md-10">
						<input type="file" class="form-control" name="eventImg"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="start_date" class="col-md-2 control-label">기간</label>
					<div class="col-md-10 input-group input-group-sm">
						<input type="datetime-local" class="form-control" name="start_date">
						<span class="input-group-addon addon">~</span>
						<input type="datetime-local" class="form-control" name="end_date">
					</div>
				</div>
				
				<div class="form-group">
					<label for="boardText" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea id="boardText" name="boardText" class="form-control" rows="10" placeholder="내용을 입력하세요"></textarea>
					</div>
				</div>
				
				<div class="form-group">
					<label for="eventType" class="col-md-2 control-label">이벤트 구분</label>
					<div class="col-md-10">
						<select name="eventType" class="form-control">
							<option>- 선택하세요 -</option>
							<c:forEach items="${eventType}" var="list">
								<option value="${list.idCommon}">${list.commonText}</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="eventLinkCode" class="col-md-2 control-label">링크코드</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="eventLinkCode" placeholder="링크코드를 입력하세요"/>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">저장하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#insertEvent").submit(function() {
				
				if (!$("input[name='boardTitle']").val().isValue()) {
					alert("이벤트명을 입력하세요.");
					$("input[name='boardTitle']").focus();
					return false;
				}
				
				if ($("select[name='brand'] > option:selected").index() < 1) {
					alert("클라이언트를 선택하세요.");
					$("select[name='brand']").focus();
					return false;
				}
				
				var image = true;
				$("input[name='eventImg']").each(function(idx, item) {
					if (!$(item).val().isValue()) {
						alert("사진을 추가하세요.");
						$(item).focus();
						image = false;
					}
				});
				if (!image) {
					return false;
				}
				
				if (!$("input[name='start_date']").val().isValue()) {
					alert("시작일을 입력하세요.");
					$("input[name='start_date']").focus();
					return false;
				}
				
				if (!$("input[name='end_date']").val().isValue()) {
					alert("종료일를 입력하세요.");
					$("input[name='end_date']").focus();
					return false;
				}
				
				if (!$("textarea[name='boardText']").val().isValue()) {
					alert("내용을 입력하세요.");
					$("textarea[name='boardText']").focus();
					return false;
				}
				
				if ($("select[name='eventType'] > option:selected").index() < 1) {
					alert("이벤트 구분을 선택하세요.");
					$("select[name='eventType']").focus();
					return false;
				}
				
				if (!$("input[name='eventLinkCode']").val().isValue()) {
					alert("링크코드를 입력하세요.");
					$("input[name='eventLinkCode']").focus();
					return false;
				}
				
				if (!confirm("정말 등록하시겠습니까?")) {
					return false;
				}
			});
			
		});
	</script>
  </body>
</html>